
<template>
  <div id="card_write_off_input">
		<magic-header v-if="!isWxPublic" titleName="扫码核销"></magic-header>
    <section>
        <div class="card_number">
        <input type="text" v-model="cardNumber" placeholder="请输入卡券码">
      </div>
      <div class="apply">
        <input @click="submit" type="button" value="确定">
      </div>
    </section>
  </div>
</template>
<script>
import magicHeader from "components/magicHeader";
import cardWriteOff from "services/vfhz/card_write_off";
export default {
  name: "card_write_off_input",
  data() {
    return {
      userId: "",
      shopId: "",
      cardNumber: "",
      isWxPublic:false
    };
  },
  created() {
    if (this.$.env === "wxPublic") {
      this.isWxPublic = true;
    }
    this.userId = this.$.userId;
    this.shopId = this.$.shopId;

  },
  methods: {
     submit(){
       if(this.cardNumber.length === 0){
         this.$.toast('卡券不能为空');
         return;
       }
       console.log(this.cardNumber);
          cardWriteOff.bind(this)({
            methodName : "VerificationCoupon", 
            shopId:this.shopId,
            userId:this.userId,
            couponCodeId : this.cardNumber
          },res => {
              console.log(res)
              if(res.success === true){
                  this.$router.push({
                      name:'card_write_off_success'
                  })
              }
          },err =>{
              console.log(err)
              switch (err) {
                    case "卡券不支持扫码核销":
                      this.$.toast("该券仅限V商在线消费时使用，请告知用户");
                      break;
                    case "卡券所属店铺和管理员所属店铺不一致":
                      this.$.toast("该卡券非贵店铺发放");
                      break;
                    case "卡券已失效":
                      this.$.toast("该券已失效");
                      break;
                  }
          })
    }
  },
  components: {
    magicHeader
  }
};
</script>
<style scoped="scoped" lang="scss">
#card_write_off_input {
  text-align: center;
  font-size: 14px;
  input {
    width: 80vw;
    height: 46px;
    line-height: 46px;
    border-radius: 5px;
    border: none;
    font-size: 14px;
  }
  .card_number {
    input {
      border: 1px solid #929292;
      margin: 20px auto;
      padding: 0 5px;
    }
  }
  .apply {
    input {
      background-color: #fb8713;
      color: #fff;
      font-size: 14px;
    }
  }
}
</style>